1 package cz
.brmlab
.brmtron
.server
.test
;
3 import static org
.junit
.Assert
.*;
5 import java
.util
.Random
;
9 import cz
.brmlab
.brmtron
.server
.BrmTronServer
;
10 import cz
.brmlab
.brmtron
.server
.PathElement
;
12 public class BrmTronServerTest
extends BrmTronServer
{
15 public void test_calcIntersection() {
16 final double dx
= 1e-09;
18 double[] start1
= {0.0, 0.0};
19 double[] end1
= {0.0, 2.0};
20 double[] start2
= {-1.0, 0.0};
21 double[] end2
= {1.0, 2.0};
23 double[] res
= {0.0, 1.0};
25 PathElement e1
= new PathElement(start1
, end1
);
26 PathElement e2
= new PathElement(start2
, end2
);
28 double[] brm
= BrmTronServer
.calcIntersection(e1
, e2
);
30 assertTrue(compareDouble(brm
, res
, dx
));
34 public void test1_findIntersection() {
35 final double dx
= 1e-09;
37 double[] start1
= {0.0, 0.0};
38 double[] end1
= {0.0, 2.0};
39 double[] start2
= {-1.0, 0.0};
40 double[] end2
= {1.0, 2.0};
42 double[] res
= {0.0, 1.0};
44 PathElement e1
= new PathElement(start1
, end1
);
45 PathElement e2
= new PathElement(start2
, end2
);
47 double[] brm
= BrmTronServer
.findIntersection(e1
, e2
);
49 assertTrue(compareDouble(brm
, res
, dx
) );
53 public void test2_findIntersection() {
54 final double dx
= 1e-09;
56 double[] start1
= {0.1, 0.1};
57 double[] end1
= {0.0, 2.0};
58 double[] start2
= {-1.0, 0.2};
59 double[] end2
= {1.0, 200.0};
63 PathElement e1
= new PathElement(start1
, end1
);
64 PathElement e2
= new PathElement(start2
, end2
);
66 double[] brm
= BrmTronServer
.findIntersection(e1
, e2
);
68 assertTrue(compareDouble(brm
, res
, dx
));
72 public void test1_checkForCollision() {
74 double[] start
= {0,1};
75 double [] end
= {1,0};
76 PathElement p
= new PathElement(start
, end
);
78 assertFalse(checkForCollision(p
) == null);
83 assertTrue(checkForCollision(p
) == null);
86 private boolean compareDouble(double[] a
, double[] b
, double dx
) {
87 if(a
== null && b
== null)
89 if((a
== null && b
!= null) || (a
!= null && b
==null))
92 for(int i
=0; i
<a
.length
; i
++) {
93 if(Math
.abs(a
[i
]-b
[i
]) > dx
) {
102 private void generateWalls(int n
) {
103 Random r
= new Random();
104 double[] start
= {0,0};
105 double[] end
= {0,0};
108 end
[0] = start
[0] + r
.nextDouble();
109 end
[1] = start
[1] + r
.nextDouble();
110 PathElement p
= new PathElement(start
, end
);